
// 输入的参赛人员姓名格式校验串，之间用英文逗号隔开
var REG_NAME_COMMA = /^([0-9|a-z|A-Z|\u4e00-\u9fa5])+(,[0-9|a-z|A-Z|\u4e00-\u9fa5]+)*$/; 
// 手机号码格式校验串
var REG_MOBILE_PATTERN = /^1[3-9]{1}[0-9]{9}$/;
	
function createOptions(id,val)
	{
		if(null == id || "" == id)
		{
			return "";
		}
		return "<option value='" + id + "'>" + val + "</option>";
}

// 根据type查询复合字典列表
function setSubCategory(obj,renderId)
{
	var options = "<option value='' selected='selected'>展示小类</option>";
	var val = obj.value;
	if("other" == val)
	{
		$("#"+renderId).hide();
		$("#" + renderId).html("");
		return;
	}
	else
	{
		$("#"+renderId).show();
	}
	var type = $(obj).find("option:selected").attr("type");
	var subType = type + "_" + val;
	$.ajax({
	       type: "POST",
	       url: ctx+"/ems/qryCategory",
	       dataType: "text",
	       data:"type="+subType,
		   async: true,
	       success: function(jsonArea){
		       // 转换为json对象
		       jsonArea = eval('(' + jsonArea + ')');
		       
			   for(var area in jsonArea)
		   	   {
		   	  	 var value = jsonArea[area].value;
		   	  	 var name = jsonArea[area].name;
		   	  	 options += createOptions(value,name);
		   	   }
			   $("#" + renderId).html("");
		   	   $("#" + renderId).html(options);
		   	   $("#" + renderId).change();
	       }
	    });
}

/**
 * 判空公共方法
 * @param title 提示标题
 * @param objId 判空对象id
 * @param type  判空对象类型
 * @param type  值长度上限
 * @returns {Boolean}
 */
function isNull(title,objId,type,length)
{
	if(type == "text")
	{
		var val = $("#"+objId).val();
		if(!$("#"+objId)[0])
		{
			return false;
		}
		if(null == val || "" == val)
		{
			alert(title + ":不能为空。");
			$("#"+objId).focus();
			return true;
		}else if(null !== length && length > 0)
		{
			if(val.length > length)
			{
				alert(title + ":长度不能超过" + length);
				$("#"+objId).focus();
				return true;
			}
		}
		return false;
	}else
	if(type == "checkBox" || type == "radio")
	{
		var hasChecked = false;
		$('input[name="' + objId + '"]').each(
			function (i,item)
			{
				if(item.checked)
				{
					hasChecked = true;
				}
			}
		);
		if(!hasChecked)
		{
			alert("请勾选 " + title + "。");
			return true;
		}
		return false;
	}else
	if(type == "select")
	{
		if(!$("#"+objId)[0])
		{
			return false;
		}
		
		var val = $("#"+objId).val();
		if(null == val || "" == val)
		{
			alert("请选择  " + title + "。");
			$("#"+objId).focus();
			return true;
		}
		return false;
	}else
	if(type == "textarea")
	{
		var val = $("#"+objId).val();
		if(null == val || "" == val || "最多输入200字" == val)
		{
			alert(title + ":不能为空。");
			$("#"+objId).focus();
			return true;
		}
		return false;
	}else
	if(type == "number")
	{
		var val = $("#"+objId).val();
		if(null != val && "" != val)
		{
			//alert((/^[1-9][0-9]{1}$/g).test(80));
			if(!((/^\d+$/g).test(val)))
			{
				$("#"+objId).focus();
				alert(title + " 只能输入数字，请重新输入。");
				return true;
			}
			else
			{
				// 数字为100时，符合要求
				if(val == "100")
				{
					return false;
				}else
				if((/^\d+$/g).test(length))
				{
					if(val.length > length)
					{
						alert(title + " 只能输入"+length+"位数字。");
						return true;
					}
				}
			}
		}
		return false;
	}
	
}

// 判断字符串str是否以strEnd结尾
function endWith(str,strEnd)
{
	if(!str || !strEnd || str.length < strEnd.length)
	{
		return false;
	}
	var subEnd = str.substring((str.length - strEnd.length),str.length);
	return subEnd == strEnd;
}


function alertMsg(msg)
{
	swal({
	    title: msg,
	    text: msg,
	    type: "error",
	    confirmButtonColor: "#09c",
	    confirmButtonText: "返回",
	    closeOnConfirm: true
	});
}

/**
 swal({
    title: "请选择充值金额",
    text: "请选择一个充值金额",
    type: "error",
    confirmButtonColor: "#09c",
    confirmButtonText: "返回",
    closeOnConfirm: true
});
 * */

/**
swal({
   title: "请选择充值金额",
   text: "请选择一个充值金额",
   type: "error",
   confirmButtonColor: "#09c",
   confirmButtonText: "返回",
   closeOnConfirm: true
});
* */


/**
 swal({
    title: "",
    text: msg,
    type: "error",
    confirmButtonColor: "#09c",
    confirmButtonText: "返回",
    closeOnConfirm: true
}, function() {
	window.location.href='${pageContext.request.contextPath}/app/card/dianxinIndex';
});
 * */

